package com.lfnyxy.service.org.imp;
import com.lfnyxy.dao.org.EmpowerDao;
import com.lfnyxy.entity.org.EmpowerEntity;
import com.lfnyxy.query.org.EmpowerQuery;
import com.lfnyxy.service.org.EmpowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpowerServiceImp implements EmpowerService {
    @Autowired
    public EmpowerDao empowerDao;

    public int CreateItem(EmpowerEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return empowerDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(EmpowerEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return empowerDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List<EmpowerEntity> QueryPageList(EmpowerQuery query) {
        int count = empowerDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return empowerDao.QueryPageList(query);
        }
        return null;
    }

    public List<EmpowerEntity> QueryAll() {
        return empowerDao.QueryAll();
    }

    public EmpowerEntity QueryItem(int Id) {
        if (Id > 0) {
            return empowerDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return empowerDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(EmpowerEntity entity) {
        if (entity != null) {
            return empowerDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}